<template>
  <div>
    <div style="margin-bottom: 10px; font-size: 14px; font-weight: 250; margin-left: 10px">
      <el-icon><Memo /></el-icon>
      授课查询
    </div>
    <el-card style>
      <el-table :data="data.tableData" stripe style="width: 100%">
        <el-table-column prop="id" label="课程ID" />
        <el-table-column prop="name" label="课程名" />
        <el-table-column prop="grade" label="年级" />
        <el-table-column prop="credit" label="学分" />
        <el-table-column label="上课时间">
          <template #default="scope">
            {{ formatTimeDisplay(scope.row.time) }}
          </template>
        </el-table-column>
        <el-table-column prop="location" label="上课地点" />
        <el-table-column prop="selectCount" label="选课人数" />
      </el-table>
      <div style="display: flex; justify-content: center; margin-top: 10px">
        <el-pagination layout="prev, pager, next" :total="data.tableData.length" :page-size="10" />
      </div>
    </el-card>
  </div>
</template>

<script setup>

import {reactive} from "vue";
import request from "@/utils/request.js";
import {formatCourseTime} from "@/utils/timeFormatter.js";

const data = reactive({
  tableData: [],
})

const teacher = JSON.parse(localStorage.getItem("teacher"))

const load = () => {
  request.get("teacher/selectAllCourse/" + teacher.id).then(res => {
    data.tableData = res.data
  })
}

load()

const formatTimeDisplay = (timeStr) => {
  return formatCourseTime(timeStr);
};
</script>